{extend name="app/admin/view/base.html"/}
{block name="resources"}
{/block}
{block name="main"}
<div class="layui-collapse ns-tips">
	<div class="layui-colla-item">
		<ul class="layui-colla-content layui-show">
			<li>活动名称：{$game_info.game_name} ({:date('Y-m-d H:i:s',$game_info.start_time)} -- {:date('Y-m-d H:i:s',$game_info.end_time)}) </li>
			<li>参与条件：{$game_info.level_name} </li>
			<li>消耗积分：{$game_info.points}</li>
			<li>参与次数：{if $game_info.join_type == 1} 每天{$game_info.join_frequency}次{else/} 一人{$game_info.join_frequency}次{/if}</li>
			<li>中奖概率：{$game_info.winning_rate}%</li>
		</ul>
	</div>
</div>

<!-- 搜索框 -->
<div class="ns-single-filter-box">

	<div class="layui-form">
		<div class="layui-inline">
			<div class="layui-input-inline">
				<input type="text" name="member_nick_name" placeholder="会员昵称" class="layui-input" autocomplete="off">
			</div>
		</div>
		<div class="layui-inline">
			<div class="layui-input-inline">
				<input type="text" name="start_time" id="start_time" placeholder="开始时间" class="layui-input" autocomplete="off" readonly>
				<i class="ns-calendar"></i>
			</div>
			<div class="layui-input-inline end-time">
				<input type="text" name="end_time" id="end_time" placeholder="结束时间" class="layui-input" autocomplete="off" readonly>
				<i class="ns-calendar"></i>
			</div>
			<button class="layui-btn layui-btn-primary" lay-submit lay-filter="search">搜索</button>
		</div>
	</div>

</div>

<div class="layui-tab ns-table-tab" lay-filter="record_tab">
	<ul class="layui-tab-title">
		<li class="layui-this" data-status="">全部</li>
		<li data-status="1">中奖</li>
		<li data-status="0">未中奖</li>
	</ul>
	<div class="layui-tab-content">
		<!-- 列表 -->
		<table id="record_list" lay-filter="record_list"></table>
	</div>
</div>

{/block}

{block name="script"}
<script>

    var game_id = "{$game_id}";
    layui.use(['form', 'element','laydate'], function() {
        var table,
            form = layui.form,
            laydate = layui.laydate,
            element = layui.element,
            repeat_flag = false; //防重复标识
        form.render();

        //开始时间
        laydate.render({
            elem: '#start_time' //指定元素
            ,done: function(value, date, endDate){
                start_time = ns.date_to_time(value);

            }
        });
        //结束时间
        laydate.render({
            elem: '#end_time' //指定元素
            ,done: function(value, date, endDate){
                end_time = ns.date_to_time(value);
            }
        });

        //监听Tab切换，以改变地址hash值
        element.on('tab(record_tab)', function() {
            table.reload({
                page: {
                    curr: 1
                },
                where: {
                    'status': this.getAttribute('data-status')
                }
            });
        });

        table = new Table({
            elem: '#record_list',
            url: ns.url("egg://admin/record/lists"),
            where:{
                'game_id':game_id
            },
            cols: [
                [{
                    field:'member_nick_name',
                    title: '会员昵称',
                    unresize: 'false',
                    width:'45%'
                }, {
                    field: '',
                    title: '中奖信息',
                    unresize: 'false',
                    templet: function(data){
                        if(data.is_winning == 1){
                            if(data.award_type == 1){
                                return data.award_name + "【"+data.point+"积分】";
                            }
                            if(data.award_type == 2){
                                return data.award_name + "【"+data.balance+"红包】";
                            }
                            if(data.award_type == 3){
                                return data.award_name + "【"+data.relate_name+"】";
                            }
                        }else{
                            return '未中奖';
                        }
                    }
                }, {
                    title: '抽奖时间',
                    unresize: 'false',
                    templet: function(data){
                        return ns.time_to_date(data.create_time);
                    }
                }]
            ]

        });

        /**
         * 搜索功能
         */
        form.on('submit(search)', function(data) {
            table.reload({
                page: {
                    curr: 1
                },
                where: data.field
            });
        });

        //监听Tab切换
        element.on('tab(status)', function(data) {
            var status = $(this).attr("data-status");
            table.reload({
                page: {
                    curr: 1
                },
                where: {
                    'status': status
                }
            });
        });

    });

</script>
{/block}